package com.young.common.client.ums;

import com.young.common.exception.BaseException;
import com.young.common.util.Result;
import com.young.common.util.StringUtils;
import com.young.interfaces.ums.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ums客户端工具
 * @author imrookie
 * @date 2018/9/5
 */
public class UmsClientHelper {

    private static Logger logger = LoggerFactory.getLogger(UmsClientHelper.class);

    /**
     * 获取当前登录用户
     * @return
     */
    public static User getLoginUser() {
        return UmsClientContext.getLoginUser();
    }

    /**
     * 获取当前登录用户id
     * @return
     */
    public static String getLoginUserId() throws BaseException {
        User user = getLoginUser();
        if (user == null || StringUtils.isBlank(user.getId())) {
            throw new BaseException(Result.CodeEnum.SESSION_TIMEOUT);
        }
        return user.getId();
    }
}
